﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>创建调度任务-Step2：设置调度模式
    </title>
    <meta name="description" content="">
    <meta name="author" content="">

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

    <!-- #CSS Links -->
    <!-- Basic Styles -->
    <link rel="stylesheet" type="text/css" media="screen" href="css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="css/font-awesome.css">

    <!-- SmartAdmin Styles : Caution! DO NOT change the order -->
    <link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-production-plugins.css">
    <link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-production.css">
    <link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-skins.css">

    <!-- SmartAdmin RTL Support -->
    <link rel="stylesheet" type="text/css" media="screen" href="css/smartadmin-rtl.css">

    <!-- Demo purpose only: goes with demo.js, you can delete this css when designing your own WebApp -->
    <link rel="stylesheet" type="text/css" media="screen" href="css/demo.css">

    <!-- #FAVICONS -->
    <link rel="shortcut icon" href="img/favicon/favicon.ico" type="image/x-icon">
    <link rel="icon" href="img/favicon/favicon.ico" type="image/x-icon">

    <!-- #GOOGLE FONT -->
    <link rel="stylesheet" href="css/open-sans.css" type="text/css">

    <!-- #APP SCREEN / ICONS -->
    <link rel="apple-touch-icon" href="img/splash/sptouch-icon-iphone.png">
    <link rel="apple-touch-icon" sizes="76x76" href="img/splash/touch-icon-ipad.png">
    <link rel="apple-touch-icon" sizes="120x120" href="img/splash/touch-icon-iphone-retina.png">
    <link rel="apple-touch-icon" sizes="152x152" href="img/splash/touch-icon-ipad-retina.png">

    <!-- iOS web-app metas : hides Safari UI Components and Changes Status Bar Appearance -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <!-- Startup image for web apps -->
    <link rel="apple-touch-startup-image" href="img/splash/ipad-landscape.png"
        media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)">
    <link rel="apple-touch-startup-image" href="img/splash/ipad-portrait.png"
        media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)">
    <link rel="apple-touch-startup-image" href="img/splash/iphone.png" media="screen and (max-device-width: 320px)">


    <link href="appcss/Common.css" rel="stylesheet" />
</head>
<body class="desktop-detected minified">

    <!-- #MAIN PANEL -->
    <div id="main" role="main">

        <!-- RIBBON -->
        <div id="ribbon">

            <span class="ribbon-button-alignment">
                <span id="refresh" class="btn btn-ribbon" data-action="resetWidgets" data-title="refresh"
                    rel="tooltip" data-placement="bottom"
                    data-original-title="<i class='text-warning fa fa-warning'></i> Warning! This will reset all your widget settings."
                    data-html="true"
                    data-reset-msg="Would you like to RESET all your saved widgets and clear LocalStorage?"><i
                        class="fa fa-home"></i></span>
            </span>

            <!-- breadcrumb -->
            <ol class="breadcrumb">
                <li>Home</li>
                <li>创建调度任务-Step2：设置调度模式</li>
            </ol>
            <!-- end breadcrumb -->

        </div>
        <!-- END RIBBON -->


        <!-- MAIN CONTENT -->
        <div id="content">
            <div class="row hidden">
                <div class="col-xs-12 col-sm-7 col-md-7 col-lg-4">
                    <h1 class="page-title txt-color-blueDark">
                        <i class="fa fa-edit fa-fw "></i>
                        主页
            <span>> 
				创建调度任务-Step2：设置调度模式
            </span>
                    </h1>
                </div>

            </div>

            <!-- widget grid -->
            <section id="widget-grid" class="">

                <!-- row -->
                <div class="row">

                    <!-- NEW WIDGET START -->


                    <!-- NEW WIDGET START -->
                    <article class="col-sm-12 col-md-12 ">

                        <!-- Widget ID (each widget will need unique ID)-->
                        <div class="jarviswidget" id="wid-id-2" data-widget-colorbutton="false"
                            data-widget-editbutton="false">
                            <header>
                                <h2>创建调度任务-Step2：设置调度模式</h2>

                            </header>

                            <!-- widget div-->
                            <div>

                                <!-- widget edit box -->
                                <div class="jarviswidget-editbox">
                                    <!-- This area used as dropdown edit box -->

                                </div>
                                <!-- end widget edit box -->

                                <!-- widget content -->
                                <div class="widget-body no-padding">

                                    <!-- Success states for elements -->

                                    <form action="" class="smart-form" id="Add-Form">
                                        <header>填写相关信息</header>
                                        <fieldset>
                                            <section>
                                                <label class="label">DataService</label>
                                                <label class="input">
                                                    <input type="text" value="DataService" id="ServiceName" disabled="disabled" />
                                                </label>
                                            </section>
                                            <section>
                                                <label class="label">Type</label>
                                                <label class="input">
                                                    <input type="text" value="WebService" id="ServiceType" disabled="disabled" />
                                                </label>
                                            </section>
                                            <section>
                                                <label class="label">DataSource</label>
                                                <label class="input">
                                                    <input type="text" value="DataSource" id="SourceName" disabled="disabled" />
                                                </label>
                                            </section>
                                            <section>
                                                <label class="label">调度服务名称</label>
                                                <label class="input">
                                                    <input type="text" value="" name="Name" class="required field" />
                                                </label>
                                            </section>
                                            <section>
                                                <div class="inline-group">
                                                    <label class="checkbox">
                                                        <input type="checkbox" id="EnableCodeConversionOption">
                                                        <i></i>启用数据审核</label>
                                                    <label class="checkbox">
                                                        <input type="checkbox" id="EnableDataVerificationOption">
                                                        <i></i>启用编码转换</label>
                                                </div>
                                            </section>
                                        </fieldset>
                                        <fieldset>
                                            <section>
                                                <label class="label">执行模式</label>

                                                <div class="inline-group">
                                                    <label class="radio ">
                                                        <input type="radio" data-type="" value="1" name="RunMode" class="TaskType" checked="checked" />
                                                        <i></i>手动
                                                    </label>
                                                    <label class="radio ">
                                                        <input type="radio" data-type="timer" value="2" class="TaskType" name="RunMode" />
                                                        <i></i>定时器
                                                    </label>
                                                    <label class="radio">
                                                        <input type="radio" data-type="alarmclock " value="3" class="TaskType" name="RunMode" />
                                                        <i></i>闹钟                                            
                                                    </label>
                                                    <label class="radio">
                                                        <input type="radio" data-type="event" value="4" class="TaskType" name="RunMode" />
                                                        <i></i>事件触发
                                                    </label>
                                                </div>
                                            </section>
                                            <section>
                                                <input value="" type="hidden" id="RunModeId" />
                                            </section>
                                        </fieldset>
                                        <fieldset id="timer" class="taskoption" style="display: none;">

                                            <section>
                                                <label class="label">开始日期</label>
                                                <label class="input">
                                                    <input type="text" onclick="WdatePicker(({ dateFmt: 'yyyy-MM-dd H:mm:ss' }))" class="typeOption timerOption Wdate" id="timer-begindata" name="timer-begindata" />
                                                </label>
                                            </section>
                                            <section>
                                                <label class="label">间隔</label>
                                                <label class="input">
                                                    <input type="text" class="typeOption timerOption" id="timer-interval-value" name="timer-interval-value" />
                                                </label>
                                            </section>
                                            <section>
                                                <label class="label">间隔单位</label>
                                                <label class="select">
                                                    <select id="timer-interval-type" name="timer-interval-type">
                                                        <option value="1">天</option>
                                                        <option value="2">小时</option>
                                                        <option value="3">分</option>
                                                    </select>
                                                </label>
                                            </section>
                                        </fieldset>
                                        <fieldset id="alarmclock" class="taskoption" style="display: none;">
                                            <section>
                                                <label class="label">类型</label>
                                                <label class="select">
                                                    <select name="alarmclock-interval-type" id="alarmclock-interval-type">
                                                        <option value="1">每年</option>
                                                        <option value="2">每月</option>
                                                        <option value="3">每周</option>
                                                        <option value="4">每天</option>
                                                    </select>
                                                </label>
                                            </section>
                                            <section>
                                                <label class="label">值</label>

                                                <label class="input" id="alarmclock-interval-value-contral">
                                                    <input type="text" class="typeOption alarmclockOption Wdate " id="alarmclock-interval-value" name="alarmclock-interval-value" />
                                                </label>
                                            </section>
                                        </fieldset>
                                        <fieldset id="event" class="taskoption" style="display: none;">
                                            <section>
                                                <label class="label">事件</label>
                                                <label class="input">
                                                    <input type="text" class="typeOption eventOption" id="event-interval-value" name="event-interval-value" />
                                                </label>
                                            </section>
                                        </fieldset>
                                        <fieldset>
                                            <section>
                                                <label class="label">参数</label>
                                                <table class="table table-bordered  table-hover smart-form"
                                                    id="table-details">
                                                    <thead>
                                                        <tr>
                                                            <th>名称</th>
                                                            <th>类型</th>
                                                            <th>数据值类型</th>
                                                            <th>值</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                    </tbody>
                                                </table>
                                            </section>
                                        </fieldset>
                                        <footer>
                                            <input type="hidden" value="Excel" name="sys:sno" />
                                            <input type="hidden" value="CreateDataService" name="sys:act" />
                                            <input type="hidden" value="" name="DataServiceId" id="DataServiceId" />
                                            <input type="hidden" value="" name="DataSourceId" id="DataSourceId" />
                                            <input type="hidden" value="" name="EnableCodeConversion" id="EnableCodeConversion" />
                                            <input type="hidden" value="" name="ParameterSettings" id="ParameterSettings" />
                                            <input type="hidden" value="" name="RunModeSettings" id="RunModeSettings" />
                                            <input type="hidden" value="" name="EnableDataVerification" id="EnableDataVerification" />
                                            <button type="submit" class="btn btn-primary">下一步</button>
                                        </footer>
                                    </form>
                                    <!--/ Success states for elements -->
                                </div>
                                <!-- end widget content -->
                            </div>
                            <!-- end widget div -->
                        </div>
                        <!-- end widget -->
                    </article>
                </div>

                <!-- end row -->

            </section>
        </div>
        <!-- END MAIN CONTENT -->
    </div>


    <!--================================================== -->

    <!-- PACE LOADER - turn this on if you want ajax loading to show (caution: uses lots of memory on iDevices)
<script data-pace-options='{ "restartOnRequestAfter": true }' src="js/plugin/pace/pace.min.js"></script>-->


    <!-- #PLUGINS -->
    <!-- Link to Google CDN's jQuery + jQueryUI; fall back to local -->
    

    <script src="js/libs/jquery-2.1.1.min.js"></script>
    <script src="js/libs/jquery-ui-1.10.3.min.js"></script>
    <!-- BOOTSTRAP JS -->
    <script src="js/bootstrap/bootstrap.min.js"></script>

    <!-- IMPORTANT: APP CONFIG -->
    <script src="js/app.config.js"></script>


    <!-- CUSTOM NOTIFICATION -->
    <script src="js/notification/SmartNotification.min.js"></script>

    <!-- JARVIS WIDGETS -->
    <script src="js/smartwidgets/jarvis.widget.min.js"></script>


    <!-- SPARKLINES -->
    <script src="js/plugin/sparkline/jquery.sparkline.min.js"></script>

    <!-- JQUERY MASKED INPUT -->
    <script src="js/plugin/masked-input/jquery.maskedinput.min.js"></script>


    <!-- JQUERY UI + Bootstrap Slider -->
    <script src="js/plugin/bootstrap-slider/bootstrap-slider.min.js"></script>

    <script src="js/plugin/My97DatePicker/WdatePicker.js"></script>
    <script src="appjs/Common.js"></script>
    <script src="appjs/Helper.js"></script>

    <script>
        var serviceId = GetQueryString("Id");
        var sourceId = GetQueryString("dataSourceId");
        var ServiceTypelist = GetDataServiceTypeList();
        $(function () {
            //执行初始化
            getServiceDetails();
            getDataSourceDetails();
            $(".TaskType").change(function () {
                var id = $(this).attr("data-type");
                $(".taskoption").hide();
                if (id != "") {
                    $("#" + id).show();
                }
                $("#RunModeId").val($(this).val());
                $(".typeOption").removeClass("required");
                $("." + id + "Option").addClass("required");
            });
            $("#alarmclock-interval-type").change(function () {
                var id = parseInt($(this).val());
                $("#alarmclock-interval-value").val("");

            });
            $("#alarmclock-interval-value").click(function () {
                var id = parseInt($("#alarmclock-interval-type").val());
                switch (id) {
                    case 1:
                        WdatePicker(({ dateFmt: 'MM-dd' }));
                        break;
                    case 2:
                        WdatePicker(({ dateFmt: 'dd' }));
                        break;
                    case 3:

                        break;
                    case 4:
                        WdatePicker(({ dateFmt: 'HH:mm:ss' }));
                        break;
                }
            });
            $("#alarmclock-interval-value").blur(function () {
                var id = parseInt($("#alarmclock-interval-type").val());
                if (id == 3) {
                    var reg = new RegExp("^[1-7]{1}$");
                    if (!reg.test($("#alarmclock-interval-value").val())) {
                        ShowGritter("请输入数字1到7");
                        $("#alarmclock-interval-value").val("");
                    }
                }
            });
            $("#Add-Form").validate({
                submitHandler: function (form) {
                    var runModeSettings = "";
                    var parameterSettings = "";
                    try {
                        alert(($("#EnableCodeConversionOption").is(":checked") ? true : false));
                    } catch (e) {
                        alert(e);
                    }
                    var columns = $("#table-details tbody tr");
                    if (columns.length > 0) {
                        for (var i = 0; i < columns.length; i++) {
                            var tempjson = JSON.parse($(columns[i]).attr("data"));
                            parameterSettings += tempjson.Id + "," + $("#dtcol-type-" + tempjson.editNum).val() + "," + $("#dtcol-value-" + tempjson.editNum).val();
                            if (i != columns.length - 1)
                                parameterSettings += ",";
                        }
                    }
                    switch (parseInt($("#RunModeId").val())) {

                        case 2:
                            runModeSettings = $("#timer-begindata").val() + "," + $("#timer-interval-type").val() + "," + $("#timer-interval-value").val();
                            break;
                        case 3:
                            runModeSettings = $("#alarmclock-interval-type").val() + "," + $("#timer-interval-value").val();
                            break;
                        case 4:
                            runModeSettings = $("#event-interval-value").val();
                            break;
                    }
                    $.ajax({
                        url: g_webApiBaseUrl + "create/task",
                        data: {
                            //"sys:sno": "ETL",
                            //"sys:act": "CreateTask",
                            "DataServiceId": serviceId,
                            "DataSourceId": sourceId,
                            "RunMode": $("#RunModeId").val(),
                            "EnableCodeConversion": $("#EnableCodeConversionOption").is(":checked") ? true : false,
                            "EnableDataVerification": $("#EnableDataVerificationOption").is(":checked") ? true : false,
                            "CompleteEvent": "",
                            "RunModeSettings": runModeSettings,
                            "ParameterSettings": parameterSettings,
                            "Name": $("Name").val()
                        },
                        type: "Post",
                        dataType: "json",
                        success: function (data) {
                            if (data.IsSccuess) {
                                ShowGritter("新增成功");
                                updateDataServiceFolderTree();
                                document.getElementById("add-Folder").reset();
                                $('#AddModel').modal("hide");
                            } else {
                                if (IsLogined(data.ErrorCode)) {
                                    alert("失败（" + "错误代码：" + data.ErrorCode + "，错误信息：" + data.Message + ")");
                                }
                            }
                        },
                        beforeSend: function () {
                            ShowGritter("提交中");
                        }, error: function () {
                            alert("系统异常，请稍后再试");
                        }
                    });

                }
            });
        });
        //获取服务的详细信息
        var getServiceDetails = function () {
            $.ajax({
                url: apiUrl,
                data: {
                    "sys:sno": "ETL",
                    "sys:act": "GetDataService",
                    "DataServiceId": serviceId
                },
                dataType: "json",
                success: function (data) {
                    if (data.IsSccuess) {
                        $("#ServiceName").val(data.Data.Name);
                        $("#ServiceType").val(getServiceTypeName(data.Data.TypeId));
                    } else {
                        if (IsLogined(data.ErrorCode)) {
                            alert(data.Message);
                        }
                    }
                },
                beforeSend: function () {
                    // $("btn_login").html("登录中...");
                }
            });
        }
        //获取数据源
        var getDataSourceDetails = function () {
            $.ajax({
                url: apiUrl,
                data: {
                    "sys:sno": "ETL",
                    "sys:act": "GetDataSource",
                    "DataServiceId": serviceId,
                    "DataSourceId": sourceId
                },
                dataType: "json",
                success: function (data) {
                    if (data.IsSccuess) {
                        var str = "";
                        $("#SourceName").val(data.Data.Name);//名称
                        ProductionTable(data.Data.Parameters);
                        //AppadParameterData(data.Data.Parameters);//组装数据并并填充表格
                    } else {
                        if (IsLogined(data.ErrorCode)) {
                            alert(data.Message);
                        }
                    }
                },
                beforeSend: function () {
                    // $("btn_login").html("登录中...");
                }
            });
        }
        var getServiceTypeName = function (typeId) {
            if (ServiceTypelist != null && ServiceTypelist.length != 0) {
                for (var i = 0; i < ServiceTypelist.length; i++) {
                    if (typeId == ServiceTypelist[i].Id) {
                        return ServiceTypelist[i].Caption;
                    }
                }
            }
            return "暂无";
        }


        var ProductionTable = function (data) {

            var trlist = "";
            for (var i = 0; i < data.length; i++) {
                var $this = data[i];
                trlist += AssembleData({ name: $this.Name, type: $this.Type, editNum: i, Id: $this.Id });
            }
            $("#table-details").append(trlist);


        }

        //传入data对象返回一行的表格数据
        var AssembleData = function (data) {
            var tr = ("<tr data='" + JSON.stringify(data) + "'><td>");
            tr += (data.name + "</td>");
            tr += ("<td>" + data.type + "</td>");
            tr += ("<td><select id=\"dtcol-type-" + data.editNum + "\"  >");
            tr += "<option value=\"1\">具体值</option>";
            tr += "<option value=\"2\">表达式</option>";
            tr += ("</select></td>");
            if (data.type) {

            } else if (data.type == "") {

            }
            tr += ("<td><input type=\"text\" value=\"\" name='dtcol-value-" + data.editNum + "'  id=\"dtcol-value-" + data.editNum + "\"  /></td></tr>");
            return tr;
        }

    </script>

    <script src="js/plugin/jquery-validate/jquery.validate.min.js"></script>
    <script src="js/plugin/jquery-validate/jquery.metadata.js"></script>
    <script src="js/plugin/jquery-validate/messages_cn.js"></script>

    <script src="js/app.min.js"></script>
    <script src="appjs/Helper.js"></script>
    <script src="appjs/Common.js"></script>

</body>
</html>
